package com.raysweather.android;

import android.app.Activity;
import android.os.Bundle;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.AdapterView;
import android.widget.AdapterView.OnItemSelectedListener;
import android.widget.ArrayAdapter;
import android.widget.RadioButton;
import android.widget.Spinner;
import android.widget.Toast;

public class Settings extends Activity {
	private RaysWeather rw;
	
	/** Called when the activity is first created. */
	@Override
	public void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		setContentView(R.layout.settings);
		rw = RaysWeather.getInstance();
		int delay = rw.getDelay();
		if(delay==15)
			((RadioButton)findViewById(R.id.fifteen_min)).setChecked(true);
		else if(delay==30)
			((RadioButton)findViewById(R.id.thirty_min)).setChecked(true);
		else
			((RadioButton)findViewById(R.id.sixty_min)).setChecked(true);
		
		((RadioButton)findViewById(R.id.fifteen_min)).setOnClickListener(radio_listener);
		((RadioButton)findViewById(R.id.thirty_min)).setOnClickListener(radio_listener);
		((RadioButton)findViewById(R.id.sixty_min)).setOnClickListener(radio_listener);
		
		Spinner spinner = (Spinner) findViewById(R.id.location_spinner);
		ArrayAdapter<CharSequence> adapter = ArrayAdapter.createFromResource(
				this, R.array.stations_array, android.R.layout.simple_spinner_item);
		adapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
		spinner.setAdapter(adapter);
		spinner.setOnItemSelectedListener(new LocationSelect());
		spinner.setSelection(rw.getLocation());
	}
	
	class LocationSelect implements OnItemSelectedListener {

	    public void onItemSelected(AdapterView<?> parent, View view, int pos, long id) {
	    	rw.setLocation(pos);
	    }

	    public void onNothingSelected(AdapterView parent) {
	      // Do nothing.
	    }
	}
	
	private OnClickListener radio_listener = new OnClickListener() {
	    public void onClick(View v) {
	        // Perform action on clicks
	        RadioButton rb = (RadioButton) v;
	        int delay=15;
	        if(rb.getId() == R.id.fifteen_min){
	        	delay=15;
	        }else if(rb.getId() == R.id.thirty_min){
	        	delay=30;
	        }else{
	        	delay=60;
	        }
//	        rw.setDelay(delay);
	    }
	};
	


}